package com.xufeng.demo.handler;

import cn.springmix.base.lang.entity.R;
import cn.springmix.core.exception.GlobalExceptionHandler;
import cn.springmix.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author xufeng
 * @description: 测试扩展异常
 * @date 2022-04-21 11:11
 */
@Slf4j
@Component
public class CustomExceptionHandler extends GlobalExceptionHandler {

    /**
     * 统一业务异常统一处理方法
     */
    @ExceptionHandler(ServiceException.class)
    public R<?> handleServiceException(ServiceException e) {
        R result = new R<>();
        result.setCode(e.getCode());
        result.setMessage("扩展异常");
        log.error(String.format("业务异常:%s", e.getMessage()), e);
        return result;
    }

}
